<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>04加加减减</title>
</head>

<body>
    <!-- 点击生成按钮, 新增一个li(20以内的随机数字)和删除按钮, 点击删除按钮, 删除对应的li和值 -->
    <div id="app">
        <ul>
            <li v-for="(item,index) in list" :key="item.id">
                {{item.value}}
                <button @click="del(item.id)">删除</button>

            </li>
        </ul>
        <button @click="add">生成</button>
    </div>

    <script src="../vue.js"></script>
    <script>
        const app = new Vue({
            el: '#app',
            data: {
                list:[]
            },
            methods: {
                add() {
                    this.list.push({
                        id: Date.now(),
                        value: Math.floor(Math.random() * 20)
                    })
                },
                del(id) {
                    this.list = this.list.filter(item => item.id !== id)
                }
            }
        })
    </script>
</body>

</html>